package com.xfzp.d3;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 三维世界
 * 
 * @author AndroidApe
 * @version 2011-11-10
 */
public class World {
	private List<Shape> shapes;

	public World() {
		shapes = new ArrayList<Shape>();
	}

	/**
	 * 添加形状，自动生成名字。返回形状的ID
	 * 
	 * @param shape
	 * @return
	 */
	public int add(Shape shape) {
		int r = shapes.size();
		shapes.add(r, shape);
		return r;
	}

	/**
	 * 批量添加形状
	 * 
	 * @param shapes
	 * @return
	 */
	public void add(Collection<Shape> shapes) {
		for (Shape s : shapes) {
			this.shapes.add(s);
		}
	}

	/**
	 * 批量添加形状
	 * 
	 * @param shapes
	 * @return
	 */
	public void add(Shape[] shapes) {
		for (Shape s : shapes) {
			this.shapes.add(s);
		}
	}

	/**
	 * 返回指定名称的形状
	 * 
	 * @param name
	 * @return
	 */
	public Shape get(int index) {
		return shapes.get(index);
	}

	/**
	 * 返回所有形状
	 * 
	 * @return
	 */
	public List<Shape> shapes() {
		return shapes;
	}

	/**
	 * 乘以一个4 x 4的矩阵
	 * 
	 * @param m
	 */
	public void multiply(float[] m) {
		for (Shape s : shapes) {
			s.multiply(m);
		}
	}
}
